#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/25 21:35
# @Author  : AshJo
# @Desc    : 反射的举例
# @Filename: ref_file.py
# @Version : v1.0
"""

# 文件操作

class File:
    lst = [('读取', 'read'), ('写入', 'write'),
           ('删除', 'delete'), ('重命名', 'rename'), ('移动', 'move')
           ]

    def __init__(self, filepath):
        self.filepath = filepath

    def read(self):
        print('in read func')

    def write(self):
        print('in write func')

    def delete(self):
        print('in delete func')

    def rename(self):
        print('in rename func')

    def move(self):
        print('in move func')


f = File('filepath')

while True:
    for index, item in enumerate(File.lst, 1):
        print(index, item[0])
    num = int(input('请输入序号：'))
    if hasattr(f, File.lst[num - 1][1]):
        getattr(f, File.lst[num - 1][1])()


# hasattr/getattr(对象，字符串)
